﻿using UnityEngine;
using System.Collections;

public class FollowPlayer : MonoBehaviour {

    // 游戏人物对象
    private Transform player;

    public float speed = 5.0f;

	// Use this for initialization
	void Start () {
        // 通过tag查找玩家  最新方法
    //    player = GameObject.FindWithTag("Player").GetComponent<Transform>();
        // 查找Tags的player名字 string格式
        player=GameObject.FindGameObjectWithTag(Tags.player).GetComponent<Transform>();
	}
	
	// Update is called once per frame
	void Update () {
        if (player)
        {
            Vector3 TargetPosition = player.position + new Vector3(0, 3, -3);
            transform.position = Vector3.Lerp(transform.position, TargetPosition, speed);
            Quaternion tagetRotation = Quaternion.LookRotation(player.position - transform.position); // 至少现在它是固定格式 我们记住  // 向量之间的减法运算 player减去当前坐标 箭头最终方向在player身上
            transform.rotation = Quaternion.Slerp(transform.rotation, tagetRotation, speed * Time.deltaTime);
        }
	}
}
